package com.huirui.server.controller.mini.program;

import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.CouponVo;
import com.huirui.server.pojo.vo.UserCouponListVo;
import com.huirui.server.service.CouponUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/coupon")
@Slf4j
@Tag(name = "优惠券管理", description = "微信小程序优惠券管理相关")
public class CouponController {

    @Resource
    private CouponUserService couponUserService;

    @GetMapping("/list")
    @Operation(summary = "查询商城优惠券")
    public Result<List<CouponVo>> listMallCoupon(@RequestParam("type") Integer type) {
        List<CouponVo> res = couponUserService.listMallCoupon(type);
        return Result.success(res);
    }

    @PostMapping("/add")
    @Operation(summary = "用户获取优惠券")
    public Result<Void> addUserCoupon(Long couponId) {
        couponUserService.addUserCoupon(couponId);
        return Result.success();
    }

    @GetMapping("/user/coupon")
    @Operation(summary = "查询用户的优惠券")
    public Result<UserCouponListVo> listUserCouponByType(@RequestParam("type") Integer type) {
        UserCouponListVo res = couponUserService.listUserCouponByType(type);
        return Result.success(res);
    }



}
